package com.isunland.managesystem.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.ShouldGatherPayCount.GatherPayCount;
import java.util.List;

public class ShouldGatherPayCountAdapter extends ArrayAdapter<GatherPayCount> {

  /**
   * ViewHolder class for layout.<br />
   * <br />
   * Auto-created on 2016-03-04 15:27:26 by Android Layout Finder
   * (http://www.buzzingandroid.com/tools/android-layout-finder)
   */
  private static class ViewHolder {
    public final LinearLayout rootView;
    public final TextView tvUnitCount;
    public final TextView tvTypeCount;
    public final TextView tvContractDelivetyTimeCount;
    public final TextView tvHappenedCostCount;
    public final LinearLayout llAdapterUnit;
    public final LinearLayout llAdapterType;
    public final LinearLayout llAdapterTime;

    private ViewHolder(LinearLayout rootView, TextView tvUnitCount, TextView tvTypeCount,
        TextView tvContractDelivetyTimeCount, TextView tvHappenedCostCount,
        LinearLayout llAdapterUnit, LinearLayout llAdapterType, LinearLayout llAdapterTime) {
      this.rootView = rootView;
      this.tvUnitCount = tvUnitCount;
      this.tvTypeCount = tvTypeCount;
      this.tvContractDelivetyTimeCount = tvContractDelivetyTimeCount;
      this.tvHappenedCostCount = tvHappenedCostCount;
      this.llAdapterUnit = llAdapterUnit;
      this.llAdapterType = llAdapterType;
      this.llAdapterTime = llAdapterTime;
    }

    public static ViewHolder create(LinearLayout rootView) {
      TextView tvUnitCount = (TextView) rootView.findViewById(R.id.tv_unit_count);
      TextView tvTypeCount = (TextView) rootView.findViewById(R.id.tv_type_count);
      TextView tvContractDelivetyTimeCount =
          (TextView) rootView.findViewById(R.id.tv_contractDelivetyTime_count);
      TextView tvHappenedCostCount = (TextView) rootView.findViewById(R.id.tv_happenedCost_count);
      LinearLayout llAdapterUnit = (LinearLayout) rootView.findViewById(R.id.ll_adapter_unit);
      LinearLayout llAdapterType = (LinearLayout) rootView.findViewById(R.id.ll_adapter_type);
      LinearLayout llAdapterTime = (LinearLayout) rootView.findViewById(R.id.ll_adapter_time);
      return new ViewHolder(rootView, tvUnitCount, tvTypeCount, tvContractDelivetyTimeCount,
          tvHappenedCostCount, llAdapterUnit, llAdapterType, llAdapterTime);
    }
  }

  @Override public View getView(int position, View convertView, ViewGroup parent) {
    final ViewHolder vh;
    if (convertView == null) {
      View view = mInflater.inflate(R.layout.adapter_gather_pay_count, parent, false);
      vh = ViewHolder.create((LinearLayout) view);
      view.setTag(vh);
    } else {
      vh = (ViewHolder) convertView.getTag();
    }

    GatherPayCount item = getItem(position);

    if (TextUtils.isEmpty(item.getPartName())) {
      vh.llAdapterUnit.setVisibility(View.GONE);
    } else {
      vh.llAdapterUnit.setVisibility(View.VISIBLE);
      vh.tvUnitCount.setText(item.getPartName());
    }

    if (TextUtils.isEmpty(item.getContractKindName())) {
      vh.llAdapterType.setVisibility(View.GONE);
    } else {
      vh.llAdapterType.setVisibility(View.VISIBLE);
      vh.tvTypeCount.setText(item.getContractKindName());
    }
    if (TextUtils.isEmpty(item.getOtherHelp())) {
      vh.llAdapterTime.setVisibility(View.GONE);
    } else {
      vh.llAdapterTime.setVisibility(View.VISIBLE);
      vh.tvContractDelivetyTimeCount.setText(item.getOtherHelp());
    }

    vh.tvHappenedCostCount.setText(item.getContractAmount());

    return vh.rootView;
  }

  private LayoutInflater mInflater;

  // Constructors
  public ShouldGatherPayCountAdapter(Context context, List<GatherPayCount> objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }

  public ShouldGatherPayCountAdapter(Context context, GatherPayCount[] objects) {
    super(context, 0, objects);
    this.mInflater = LayoutInflater.from(context);
  }
}
